package com.gqp.view;


import com.gqp.utils.GUIUtil;
import com.gqp.utils.StringConstant;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


/**
 * gqp 操作
 */
public class ChooseFrame extends JFrame implements ActionListener {
    /************************定义各控件******************************/


    private JButton btQueryun = new JButton("压缩文件");
    private JButton btQueryon = new JButton("解压文件");
    private JButton btExit = new JButton("退出");

    public ChooseFrame() {
        /****************************界面初始化************************/
        super("解压缩工具");
        this.setLayout(new GridLayout(3, 0));
        this.add(btQueryun);
        this.add(btQueryon);
        this.add(btExit);
        this.setSize(400, 250);
        GUIUtil.toCenter(this);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setResizable(false);
        this.setVisible(true);

        /**********************增加监听*******************************/
        btQueryun.addActionListener(this);
        btQueryon.addActionListener(this);
        btExit.addActionListener(this);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        try {
            if (e.getSource() == btQueryun) {  // 压缩文件
                new CompressFrame(StringConstant.COMPRESSION);// 压缩
                this.dispose();
            }else if(e.getSource() == btQueryon){ // 解压文件
                new CompressFrame(StringConstant.DECOMPRESSION); // 解压
                this.dispose();
            } else {
                JOptionPane.showMessageDialog(this, "欢迎再次使用");
                System.exit(0);
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }
}
